package com.timothy.fund.data;

import java.util.ArrayList;
import java.util.List;

import com.timothy.fund.bean.BaseFund;
import com.timothy.fund.http.HttpRequest;

public class SecurityData {

	private static String URL_PRE = "http://hq.sinajs.cn/list=";
	
    public static List<String> getSecurityInfoList(String securityCodes) {
    	String result =  HttpRequest.getSecurityInfoList(URL_PRE, securityCodes);
    	List<String> securityInfoList = new ArrayList<String>();
    	String[] securities = result.split(";");
        for (String security : securities) {
            String security_info = security.substring(security.indexOf("\"") + 1, security.length() - 1);
//            System.out.println(security_info);
            securityInfoList.add(security_info);
        }
        return securityInfoList;
    }
    
    
    public static List<BaseFund> getSecurityBaseBean(String securityCodes){
    	String[] sCodes = securityCodes.split(",");
    	List<BaseFund> baseBeanList = new ArrayList<BaseFund>();
        String result =  HttpRequest.getSecurityInfoList(URL_PRE, securityCodes);
        String[] sInfos = result.split(";");
        int sSeq = 0;
        for(String sInfo : sInfos){
        	String info = sInfo.substring(sInfo.indexOf("\"") + 1, sInfo.length() - 1);
            String[] datas = info.split(",");
            BaseFund bean = new BaseFund();
            bean.setQuote(sCodes[sSeq]);
            int seq=0;
            for (String data : datas) {//get name and price
            	if(seq == 0){
                    bean.setName(data);
                }
                if(seq == 3){
                    bean.setPrice(data);
                }
                seq++;
            }
            baseBeanList.add(bean);
            sSeq++;
        }
        return baseBeanList;
    }
}
